//在index.js中引入axios
import axios from 'axios';
export const postRequest = (url: string, params: any) => {
  axios({
    headers: {
      'Content-Type': 'application/json',
    },
    method: 'post',
    url: url,
    data: JSON.stringify(params),
  });
};
export const postRequestPromise = (url: string, params: any) => {
  return new Promise(((resolve, reject) => {
    axios({
      headers: {
        'Content-Type': 'application/json',
      },
      method: 'post',
      url: url,
      data: JSON.stringify(params),
    }).then(res=>{
      if(res.data.code==0)
        resolve(res.data)
      reject(res)
    }).catch(err=>{
      reject(err)
    });
  }))

};
export const postFile = (url: string, params: any, config: any) => {
  axios({
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    method: 'post',
    url: url,
    data: params,
    ...config,
  });
};
